package com.grq.mis.validate;

import com.grq.mis.entity.Department;
import com.grq.mis.exception.BusinessException;
import com.grq.mis.exception.ResultEnum;
import org.springframework.util.StringUtils;

public class DepartmentValidate {

    public static void add(Department department) {
        // name
        if (StringUtils.isEmpty(department.getName())) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "商户名称不能为空");
        }
        if (department.getName().length() > 50) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "商户名称最多为50字");
        }

        // description
        if (!StringUtils.isEmpty(department.getDescription())) {
            if (department.getDescription().length() > 255) {
                throw new BusinessException(ResultEnum.PARAM_ERROR, "商户描述最多为255字符");
            }
        }
    }

    public static void update(Department department) {
        if (department.getId() == null) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "商户ID不能为空");
        }
        // name
        if (StringUtils.isEmpty(department.getName())) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "商户名称不能为空");
        }
        if (department.getName().length() > 50) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "商户名称最多为50字");
        }

        // description
        if (!StringUtils.isEmpty(department.getDescription())) {
            if (department.getDescription().length() > 255) {
                throw new BusinessException(ResultEnum.PARAM_ERROR, "商户描述最多为255字符");
            }
        }

        if (department.getIsDisable() == null){
            throw new BusinessException(ResultEnum.PARAM_ERROR, "商户状态不能为空");
        }
    }

}
